
# 1.list  列表的相关操作有：元素访问、切片、修改、追加、插入、删除、扩展、统计、排序、下标获取、拷贝
# https://mp.weixin.qq.com/s/fPmdhe_liE-nsKvJJLVSyg

test_list = [1, "abc", 4.2, [True, 1, "14"], 1]
# 元素访问
print("1 index: %d" % test_list.index(1))


# 切片
print(test_list[1:])
print(test_list[-1])
print(test_list[-2:])
print(test_list[1::2])

# 遍历
for temp in test_list:
    print(temp, end=",")

for index in range(0, len(test_list)):
    print(test_list[index], end="，")

for index, value in enumerate(test_list):
    print("index = %d value = %s" % (index, value))



# 2.元组(Tuple) 元组中的元素不能修改，使用()小括号标识;占用更少的内存;
a = 1, 2, 4
b = (7,)
c = (7, "123a", [1, "bc", 4.5])
print("a类型为 %s" % type(a))
print("b类型为 %s" % type(b))
print("c类型为 %s" % type(c))
# c[0] = 6 报错
print(c[0])

#  tuple()函数:将字符串和列表转换为元组
d = tuple("abc")
print(d)
e = tuple([1, "abc", 4.5])
print(e)

